
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Go 语言数组 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../part13/" />
    
    
    <link rel="prev" href="../part11/" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../part1/">
            
                <a href="../part1/">
            
                    
                    Go 语言简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../part2/">
            
                <a href="../part2/">
            
                    
                    Go 语言环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../part3/">
            
                <a href="../part3/">
            
                    
                    Go 语言结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../part4/">
            
                <a href="../part4/">
            
                    
                    Go 语言基础语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../part5/">
            
                <a href="../part5/">
            
                    
                    Go 语言数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../part6/">
            
                <a href="../part6/">
            
                    
                    Go 语言变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../part7/">
            
                <a href="../part7/">
            
                    
                    Go 语言常量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../part8/">
            
                <a href="../part8/">
            
                    
                    Go 语言运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../part9/">
            
                <a href="../part9/">
            
                    
                    Go 语言条件语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../part10/">
            
                <a href="../part10/">
            
                    
                    Go 语言循环语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../part11/">
            
                <a href="../part11/">
            
                    
                    Go 语言函数
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.13" data-path="./">
            
                <a href="./">
            
                    
                    Go 语言数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../part13/">
            
                <a href="../part13/">
            
                    
                    Go 语言指针
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../part14/">
            
                <a href="../part14/">
            
                    
                    Go 语言结构体
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../part15/">
            
                <a href="../part15/">
            
                    
                    Go 语言切片(Slice)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../part16/">
            
                <a href="../part16/">
            
                    
                    Go 语言范围(Range)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../part17/">
            
                <a href="../part17/">
            
                    
                    Go 语言Map(集合)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../part18/">
            
                <a href="../part18/">
            
                    
                    Go 语言递归函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../part19/">
            
                <a href="../part19/">
            
                    
                    Go 语言类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../part20/">
            
                <a href="../part20/">
            
                    
                    Go 语言接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="../part21/">
            
                <a href="../part21/">
            
                    
                    Go 错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="../part22/">
            
                <a href="../part22/">
            
                    
                    Go 并发
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Go 语言数组</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="go-&#x8BED;&#x8A00;&#x6570;&#x7EC4;">Go &#x8BED;&#x8A00;&#x6570;&#x7EC4;</h1>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;Go &#x8BED;&#x8A00;&#x63D0;&#x4F9B;&#x4E86;&#x6570;&#x7EC4;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x3002;</p>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#x6570;&#x7EC4;&#x662F;&#x5177;&#x6709;&#x76F8;&#x540C;&#x552F;&#x4E00;&#x7C7B;&#x578B;&#x7684;&#x4E00;&#x7EC4;&#x5DF2;&#x7F16;&#x53F7;&#x4E14;&#x957F;&#x5EA6;&#x56FA;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x9879;&#x5E8F;&#x5217;&#xFF0C;&#x8FD9;&#x79CD;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x662F;&#x4EFB;&#x610F;&#x7684;&#x539F;&#x59CB;&#x7C7B;&#x578B;&#x4F8B;&#x5982;&#x6574;&#x578B;&#x3001;&#x5B57;&#x7B26;&#x4E32;&#x6216;&#x8005;&#x81EA;&#x5B9A;&#x4E49;&#x7C7B;&#x578B;&#x3002;</p>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#x76F8;&#x5BF9;&#x4E8E;&#x53BB;&#x58F0;&#x660E; <strong>number0</strong>, <strong>number1</strong>, ..., <strong>number99</strong> &#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x4F7F;&#x7528;&#x6570;&#x7EC4;&#x5F62;&#x5F0F; <strong>numbers[0]</strong>, <strong>numbers[1]</strong> ..., <strong>numbers[99]</strong> &#x66F4;&#x52A0;&#x65B9;&#x4FBF;&#x4E14;&#x6613;&#x4E8E;&#x6269;&#x5C55;&#x3002;</p>
<p>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#xFF08;&#x4F4D;&#x7F6E;&#xFF09;&#x6765;&#x8BFB;&#x53D6;&#xFF08;&#x6216;&#x8005;&#x4FEE;&#x6539;&#xFF09;&#xFF0C;&#x7D22;&#x5F15;&#x4ECE; 0 &#x5F00;&#x59CB;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7D22;&#x5F15;&#x4E3A; 0&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x7D22;&#x5F15;&#x4E3A; 1&#xFF0C;&#x4EE5;&#x6B64;&#x7C7B;&#x63A8;&#x3002;</p>
<center>
    <img style="border-radius: 0.3125em;
    box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="../source/images/part12/01.png">
    <br>
    <div style="color:orange; border-bottom: 0px solid #d9d9d9;
    display: inline-block;
    color: #999;ds
    padding: 5px;"></div>
</center>

<hr>
<h2 id="&#x58F0;&#x660E;&#x6570;&#x7EC4;">&#x58F0;&#x660E;&#x6570;&#x7EC4;</h2>
<p>Go &#x8BED;&#x8A00;&#x6570;&#x7EC4;&#x58F0;&#x660E;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x5143;&#x7D20;&#x7C7B;&#x578B;&#x53CA;&#x5143;&#x7D20;&#x4E2A;&#x6570;&#xFF0C;&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> variable_name [SIZE] variable_type
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x4E3A;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x7684;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x3002;&#x4F8B;&#x5982;&#x4EE5;&#x4E0B;&#x5B9A;&#x4E49;&#x4E86;&#x6570;&#x7EC4; balance &#x957F;&#x5EA6;&#x4E3A; 10 &#x7C7B;&#x578B;&#x4E3A; float32&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> balance [<span class="hljs-number">10</span>] <span class="hljs-keyword">float32</span>
</code></pre>
<hr>
<h2 id="&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;">&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;</h2>
<p>&#x4EE5;&#x4E0B;&#x6F14;&#x793A;&#x4E86;&#x6570;&#x7EC4;&#x521D;&#x59CB;&#x5316;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> balance = [<span class="hljs-number">5</span>] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1000.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.4</span>, <span class="hljs-number">7.0</span>, <span class="hljs-number">50.0</span>}
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5B57;&#x9762;&#x91CF;&#x5728;&#x58F0;&#x660E;&#x6570;&#x7EC4;&#x7684;&#x540C;&#x65F6;&#x5FEB;&#x901F;&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-go">balance := [<span class="hljs-number">5</span>] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1000.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.4</span>, <span class="hljs-number">7.0</span>, <span class="hljs-number">50.0</span>}
</code></pre>
<p>&#x5982;&#x679C;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x4E0D;&#x786E;&#x5B9A;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>...</code> &#x4EE3;&#x66FF;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x6839;&#x636E;&#x5143;&#x7D20;&#x4E2A;&#x6570;&#x81EA;&#x884C;&#x63A8;&#x65AD;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> balance = [...] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1000.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.4</span>, <span class="hljs-number">7.0</span>, <span class="hljs-number">50.0</span>}
<span class="hljs-comment">// &#x6216;</span>
<span class="hljs-comment">// balance := [...] float32 {1000.0, 2.0, 3.4, 7.0, 50.0}</span>
</code></pre>
<p>&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E86;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x4E0B;&#x6807;&#x6765;&#x521D;&#x59CB;&#x5316;&#x5143;&#x7D20;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-comment">//  &#x5C06;&#x7D22;&#x5F15;&#x4E3A; 1 &#x548C; 3 &#x7684;&#x5143;&#x7D20;&#x521D;&#x59CB;&#x5316;</span>
balance := [<span class="hljs-number">5</span>] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1</span>:<span class="hljs-number">2.0</span>, <span class="hljs-number">3</span>:<span class="hljs-number">7.0</span>}
</code></pre>
<p>&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;&#x4E2D; <code>{}</code> &#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E2A;&#x6570;&#x4E0D;&#x80FD;&#x5927;&#x4E8E; <code>[]</code> &#x4E2D;&#x7684;&#x6570;&#x5B57;&#x3002;</p>
<p>&#x5982;&#x679C;&#x5FFD;&#x7565; <code>[]</code> &#x4E2D;&#x7684;&#x6570;&#x5B57;&#x4E0D;&#x8BBE;&#x7F6E;&#x6570;&#x7EC4;&#x5927;&#x5C0F;&#xFF0C;Go &#x8BED;&#x8A00;&#x4F1A;&#x6839;&#x636E;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;&#x6765;&#x8BBE;&#x7F6E;&#x6570;&#x7EC4;&#x7684;&#x5927;&#x5C0F;</p>
<pre><code class="lang-go">balance[<span class="hljs-number">4</span>] = <span class="hljs-number">50.0</span>
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8BFB;&#x53D6;&#x4E86;&#x7B2C;&#x4E94;&#x4E2A;&#x5143;&#x7D20;&#x3002;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#xFF08;&#x4F4D;&#x7F6E;&#xFF09;&#x6765;&#x8BFB;&#x53D6;&#xFF08;&#x6216;&#x8005;&#x4FEE;&#x6539;&#xFF09;&#xFF0C;&#x7D22;&#x5F15;&#x4ECE; 0 &#x5F00;&#x59CB;&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x7D22;&#x5F15;&#x4E3A; 0&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x7D22;&#x5F15;&#x4E3A; 1&#xFF0C;&#x4EE5;&#x6B64;&#x7C7B;&#x63A8;&#x3002;</p>
<center>
    <img style="border-radius: 0.3125em;
    box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="../source/images/part12/02.jpg">
    <br>
    <div style="color:orange; border-bottom: 0px solid #d9d9d9;
    display: inline-block;
    color: #999;ds
    padding: 5px;"></div>
</center>

<hr>
<h2 id="&#x8BBF;&#x95EE;&#x6570;&#x7EC4;&#x5143;&#x7D20;">&#x8BBF;&#x95EE;&#x6570;&#x7EC4;&#x5143;&#x7D20;</h2>
<p>&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7D22;&#x5F15;&#xFF08;&#x4F4D;&#x7F6E;&#xFF09;&#x6765;&#x8BFB;&#x53D6;&#x3002;&#x683C;&#x5F0F;&#x4E3A;&#x6570;&#x7EC4;&#x540D;&#x540E;&#x52A0;&#x4E2D;&#x62EC;&#x53F7;&#xFF0C;&#x4E2D;&#x62EC;&#x53F7;&#x4E2D;&#x4E3A;&#x7D22;&#x5F15;&#x7684;&#x503C;&#x3002;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> salary <span class="hljs-keyword">float32</span> = balance[<span class="hljs-number">9</span>]
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8BFB;&#x53D6;&#x4E86;&#x6570;&#x7EC4; balance &#x7B2C; 10 &#x4E2A;&#x5143;&#x7D20;&#x7684;&#x503C;&#x3002;</p>
<p>&#x4EE5;&#x4E0B;&#x6F14;&#x793A;&#x4E86;&#x6570;&#x7EC4;&#x5B8C;&#x6574;&#x64CD;&#x4F5C;&#xFF08;&#x58F0;&#x660E;&#x3001;&#x8D4B;&#x503C;&#x3001;&#x8BBF;&#x95EE;&#xFF09;&#x7684;&#x5B9E;&#x4F8B;&#xFF1A;</p>
<p>&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-keyword">var</span> n [<span class="hljs-number">10</span>] <span class="hljs-keyword">int</span> <span class="hljs-comment">/* n &#x662F;&#x4E00;&#x4E2A;&#x957F;&#x5EA6;&#x4E3A; 10 &#x7684;&#x6570;&#x7EC4; */</span>
    <span class="hljs-keyword">var</span> i, j <span class="hljs-keyword">int</span>

    <span class="hljs-comment">/* &#x4E3A;&#x6570;&#x7EC4; n &#x521D;&#x59CB;&#x5316;&#x5143;&#x7D20; */</span>
    <span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">10</span>; i++ {
        n[i] = i + <span class="hljs-number">100</span> <span class="hljs-comment">/* &#x8BBE;&#x7F6E;&#x5143;&#x7D20;&#x4E3A; i + 100 */</span>
    }

    <span class="hljs-comment">/* &#x8F93;&#x51FA;&#x6BCF;&#x4E2A;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x503C; */</span>
    <span class="hljs-keyword">for</span> j = <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">10</span>; j++ {
        fmt.Printf(<span class="hljs-string">&quot;Element[%d] = %d\n&quot;</span>, j, n[j] )
    }
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x6267;&#x884C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sh">Element[0] = 100
Element[1] = 101
Element[2] = 102
Element[3] = 103
Element[4] = 104
Element[5] = 105
Element[6] = 106
Element[7] = 107
Element[8] = 108
Element[9] = 109
</code></pre>
<p>&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-keyword">var</span> i, j, k <span class="hljs-keyword">int</span>
    <span class="hljs-comment">// &#x58F0;&#x660E;&#x6570;&#x7EC4;&#x7684;&#x540C;&#x65F6;&#x5FEB;&#x901F;&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;</span>
    balance := [<span class="hljs-number">5</span>] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1000.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.4</span>, <span class="hljs-number">7.0</span>, <span class="hljs-number">50.0</span>}

    <span class="hljs-comment">/* &#x8F93;&#x51FA;&#x6570;&#x7EC4;&#x5143;&#x7D20; */</span>
    <span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">5</span>; i++ {
        fmt.Printf(<span class="hljs-string">&quot;balance[%d] = %f\n&quot;</span>, i, balance[i] )
    }

    balance2 := [...] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1000.0</span>, <span class="hljs-number">2.0</span>, <span class="hljs-number">3.4</span>, <span class="hljs-number">7.0</span>, <span class="hljs-number">50.0</span>}
    <span class="hljs-comment">/* &#x8F93;&#x51FA;&#x6BCF;&#x4E2A;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x503C; */</span>
    <span class="hljs-keyword">for</span> j = <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">5</span>; j++ {
        fmt.Printf(<span class="hljs-string">&quot;balance2[%d] = %f\n&quot;</span>, j, balance2[j] )
    }

    <span class="hljs-comment">//  &#x5C06;&#x7D22;&#x5F15;&#x4E3A; 1 &#x548C; 3 &#x7684;&#x5143;&#x7D20;&#x521D;&#x59CB;&#x5316;</span>
    balance3 := [<span class="hljs-number">5</span>] <span class="hljs-keyword">float32</span> {<span class="hljs-number">1</span>:<span class="hljs-number">2.0</span>,<span class="hljs-number">3</span>:<span class="hljs-number">7.0</span>}
    <span class="hljs-keyword">for</span> k = <span class="hljs-number">0</span>; k &lt; <span class="hljs-number">5</span>; k++ {
        fmt.Printf(<span class="hljs-string">&quot;balance3[%d] = %f\n&quot;</span>, k, balance3[k] )
    }
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x6267;&#x884C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-sh">balance[0] = 1000.000000
balance[1] = 2.000000
balance[2] = 3.400000
balance[3] = 7.000000
balance[4] = 50.000000
balance2[0] = 1000.000000
balance2[1] = 2.000000
balance2[2] = 3.400000
balance2[3] = 7.000000
balance2[4] = 50.000000
balance3[0] = 0.000000
balance3[1] = 2.000000
balance3[2] = 0.000000
balance3[3] = 7.000000
balance3[4] = 0.000000
</code></pre>
<hr>
<h2 id="&#x66F4;&#x591A;&#x5185;&#x5BB9;">&#x66F4;&#x591A;&#x5185;&#x5BB9;</h2>
<p>&#x6570;&#x7EC4;&#x5BF9; Go &#x8BED;&#x8A00;&#x6765;&#x8BF4;&#x662F;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x7684;&#xFF0C;&#x4EE5;&#x4E0B;&#x6211;&#x4EEC;&#x5C06;&#x4ECB;&#x7ECD;&#x6570;&#x7EC4;&#x66F4;&#x591A;&#x7684;&#x5185;&#x5BB9;&#xFF1A;</p>
<table>
    <tr>
        <th bgcolor="#4b4b4b"><font color="#ffffff">&#x5185;&#x5BB9;</font></th>
        <th bgcolor="#4b4b4b" width="100%"><font color="#ffffff">&#x63CF;&#x8FF0;</font></th>
    </tr>
    <tr>        
        <td align="center" bgcolor="#f5f2ee">&#x591A;&#x7EF4;&#x6570;&#x7EC4;</td>
        <td align="center" bgcolor="#f5f2ee">Go &#x8BED;&#x8A00;&#x652F;&#x6301;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x6700;&#x7B80;&#x5355;&#x7684;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x662F;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</td>
    </tr>
    <tr>        
        <td align="center" bgcolor="#ffffff">&#x5411;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x6570;&#x7EC4;</td>
        <td align="center" bgcolor="#ffffff">&#x4F60;&#x53EF;&#x4EE5;&#x5411;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x6570;&#x7EC4;&#x53C2;&#x6570;</td>
    </tr>
</table>

<h3 id="&#x591A;&#x7EF4;&#x6570;&#x7EC4;">&#x591A;&#x7EF4;&#x6570;&#x7EC4;</h3>
<p>Go &#x8BED;&#x8A00;&#x652F;&#x6301;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x4EE5;&#x4E0B;&#x4E3A;&#x5E38;&#x7528;&#x7684;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x58F0;&#x660E;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> variable_name [SIZE1][SIZE2]...[SIZEN] variable_type
</code></pre>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x58F0;&#x660E;&#x4E86;&#x4E09;&#x7EF4;&#x7684;&#x6574;&#x578B;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> threedim [<span class="hljs-number">5</span>][<span class="hljs-number">10</span>][<span class="hljs-number">4</span>] <span class="hljs-keyword">int</span>
</code></pre>
<hr>
<h4 id="&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;">&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</h4>
<p>&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x662F;&#x6700;&#x7B80;&#x5355;&#x7684;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x672C;&#x8D28;&#x4E0A;&#x662F;&#x7531;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x7EC4;&#x6210;&#x7684;&#x3002;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">var</span> arrayName [ x ][ y ] variable_type
</code></pre>
<p>variable_type &#x4E3A; Go &#x8BED;&#x8A00;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;arrayName &#x4E3A;&#x6570;&#x7EC4;&#x540D;&#xFF0C;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x53EF;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x4E2A;&#x8868;&#x683C;&#xFF0C;x &#x4E3A;&#x884C;&#xFF0C;y &#x4E3A;&#x5217;&#xFF0C;&#x4E0B;&#x56FE;&#x6F14;&#x793A;&#x4E86;&#x4E00;&#x4E2A;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4; a &#x4E3A;&#x4E09;&#x884C;&#x56DB;&#x5217;&#xFF1A;</p>
<center>
    <img style="border-radius: 0.3125em;
    box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);" src="../source/images/part12/03.jpg">
    <br>
    <div style="color:orange; border-bottom: 0px solid #d9d9d9;
    display: inline-block;
    color: #999;ds
    padding: 5px;"></div>
</center>

<p>&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x53EF;&#x901A;&#x8FC7; <code>a[i][j]</code> &#x6765;&#x8BBF;&#x95EE;&#x3002;</p>
<p>&#x5B9E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">// Step 1: &#x521B;&#x5EFA;&#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">var</span> values [][]<span class="hljs-keyword">int</span>

    <span class="hljs-comment">// Step 2: &#x4F7F;&#x7528; appped() &#x51FD;&#x6570;&#x5411;&#x7A7A;&#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x6DFB;&#x52A0;&#x4E24;&#x884C;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;</span>
    row1 := [] <span class="hljs-keyword">int</span> {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
    row2 := [] <span class="hljs-keyword">int</span> {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
    values = <span class="hljs-built_in">append</span>(values, row1)
    values = <span class="hljs-built_in">append</span>(values, row2)

    <span class="hljs-comment">// Step 3: &#x663E;&#x793A;&#x4E24;&#x884C;&#x6570;&#x636E;</span>
    fmt.Println(<span class="hljs-string">&quot;Row 1&quot;</span>)
    fmt.Println(values[<span class="hljs-number">0</span>])
    fmt.Println(<span class="hljs-string">&quot;Row 2&quot;</span>)
    fmt.Println(values[<span class="hljs-number">1</span>])

    <span class="hljs-comment">// Step 4: &#x8BBF;&#x95EE;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
    fmt.Println(<span class="hljs-string">&quot;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E3A;&#xFF1A;&quot;</span>)
    fmt.Println(values[<span class="hljs-number">0</span>][<span class="hljs-number">0</span>])
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8FD0;&#x884C;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">Row 1
[1 2 3]
Row 2
[4 5 6]
&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x4E3A;&#xFF1A;
1
</code></pre>
<hr>
<h4 id="&#x521D;&#x59CB;&#x5316;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;">&#x521D;&#x59CB;&#x5316;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</h4>
<p>&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x53EF;&#x901A;&#x8FC7;&#x5927;&#x62EC;&#x53F7;&#x6765;&#x521D;&#x59CB;&#x503C;&#x3002;&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x4E3A;&#x4E00;&#x4E2A; 3 &#x884C; 4 &#x5217;&#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-go">a := [<span class="hljs-number">3</span>][<span class="hljs-number">4</span>]<span class="hljs-keyword">int</span>{  
    {<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>},   <span class="hljs-comment">/*  &#x7B2C;&#x4E00;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 0 */</span>
    {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>},   <span class="hljs-comment">/*  &#x7B2C;&#x4E8C;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 1 */</span>
    {<span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">11</span>},   <span class="hljs-comment">/* &#x7B2C;&#x4E09;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 2 */</span>
}
</code></pre>
<ul>
<li><strong>&#x6CE8;&#x610F;</strong>&#xFF1A;&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x4E2D;&#x5012;&#x6570;&#x7B2C;&#x4E8C;&#x884C;&#x7684; <strong><code>}</code></strong> &#x5FC5;&#x987B;&#x8981;&#x6709;&#x9017;&#x53F7;&#xFF0C;&#x56E0;&#x4E3A;&#x6700;&#x540E;&#x4E00;&#x884C;&#x7684; <strong><code>}</code></strong> &#x4E0D;&#x80FD;&#x5355;&#x72EC;&#x4E00;&#x884C;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5199;&#x6210;&#x8FD9;&#x6837;&#xFF1A;<pre><code class="lang-go">  a := [<span class="hljs-number">3</span>][<span class="hljs-number">4</span>]<span class="hljs-keyword">int</span>{  
      {<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>} ,   <span class="hljs-comment">/*  &#x7B2C;&#x4E00;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 0 */</span>
      {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>} ,   <span class="hljs-comment">/*  &#x7B2C;&#x4E8C;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 1 */</span>
      {<span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>, <span class="hljs-number">11</span>}}   <span class="hljs-comment">/* &#x7B2C;&#x4E09;&#x884C;&#x7D22;&#x5F15;&#x4E3A; 2 */</span>
</code></pre>
</li>
</ul>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A; 2 &#x884C; 2 &#x5217; &#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</span>
    sites := [<span class="hljs-number">2</span>][<span class="hljs-number">2</span>]<span class="hljs-keyword">string</span>{}

    <span class="hljs-comment">// &#x5411;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x6DFB;&#x52A0;&#x5143;&#x7D20;</span>
    sites[<span class="hljs-number">0</span>][<span class="hljs-number">0</span>] = <span class="hljs-string">&quot;Google&quot;</span>
    sites[<span class="hljs-number">0</span>][<span class="hljs-number">1</span>] = <span class="hljs-string">&quot;Apple&quot;</span>
    sites[<span class="hljs-number">1</span>][<span class="hljs-number">0</span>] = <span class="hljs-string">&quot;Taobao&quot;</span>
    sites[<span class="hljs-number">1</span>][<span class="hljs-number">1</span>] = <span class="hljs-string">&quot;Weibo&quot;</span>

    <span class="hljs-comment">// &#x663E;&#x793A;&#x7ED3;&#x679C;</span>
    fmt.Println(sites)
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8FD0;&#x884C;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">[[Google Apple] [Taobao Weibo]]
</code></pre>
<hr>
<h4 id="&#x8BBF;&#x95EE;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;">&#x8BBF;&#x95EE;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</h4>
<p>&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x901A;&#x8FC7;&#x6307;&#x5B9A;&#x5750;&#x6807;&#x6765;&#x8BBF;&#x95EE;&#x3002;&#x5982;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x884C;&#x7D22;&#x5F15;&#x4E0E;&#x5217;&#x7D22;&#x5F15;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-go">val := a[<span class="hljs-number">2</span>][<span class="hljs-number">3</span>]
<span class="hljs-comment">// &#x6216;</span>
<span class="hljs-comment">// var value int = a[2][3]</span>
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8BBF;&#x95EE;&#x4E86;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4; val &#x7B2C;&#x4E09;&#x884C;&#x7684;&#x7B2C;&#x56DB;&#x4E2A;&#x5143;&#x7D20;&#x3002;</p>
<p>&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5FAA;&#x73AF;&#x5D4C;&#x5957;&#x6765;&#x8F93;&#x51FA;&#x5143;&#x7D20;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">/* &#x6570;&#x7EC4; - 5 &#x884C; 2 &#x5217;*/</span>
    <span class="hljs-keyword">var</span> a = [<span class="hljs-number">5</span>][<span class="hljs-number">2</span>] <span class="hljs-keyword">int</span> {{<span class="hljs-number">0</span>,<span class="hljs-number">0</span>}, {<span class="hljs-number">1</span>,<span class="hljs-number">2</span>}, {<span class="hljs-number">2</span>,<span class="hljs-number">4</span>}, {<span class="hljs-number">3</span>,<span class="hljs-number">6</span>}, {<span class="hljs-number">4</span>,<span class="hljs-number">8</span>}}
    <span class="hljs-keyword">var</span> i, j <span class="hljs-keyword">int</span>

    <span class="hljs-comment">/* &#x8F93;&#x51FA;&#x6570;&#x7EC4;&#x5143;&#x7D20; */</span>
    <span class="hljs-keyword">for</span>  i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">5</span>; i++ {
        <span class="hljs-keyword">for</span> j = <span class="hljs-number">0</span>; j &lt; <span class="hljs-number">2</span>; j++ {
            fmt.Printf(<span class="hljs-string">&quot;a[%d][%d] = %d\n&quot;</span>, i,j, a[i][j])
        }
    }
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8FD0;&#x884C;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">a[0][0] = 0
a[0][1] = 0
a[1][0] = 1
a[1][1] = 2
a[2][0] = 2
a[2][1] = 4
a[3][0] = 3
a[3][1] = 6
a[4][0] = 4
a[4][1] = 8
</code></pre>
<p>&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#x521B;&#x5EFA;&#x5404;&#x4E2A;&#x7EF4;&#x5EA6;&#x5143;&#x7D20;&#x6570;&#x91CF;&#x4E0D;&#x4E00;&#x81F4;&#x7684;&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x7A7A;&#x7684;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">var</span> animals [][]<span class="hljs-keyword">string</span>

    <span class="hljs-comment">// &#x521B;&#x5EFA;&#x4E09;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x5404;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x4E0D;&#x540C;</span>
    row1 := [] <span class="hljs-keyword">string</span> {<span class="hljs-string">&quot;fish&quot;</span>, <span class="hljs-string">&quot;shark&quot;</span>, <span class="hljs-string">&quot;eel&quot;</span>}
    row2 := [] <span class="hljs-keyword">string</span> {<span class="hljs-string">&quot;bird&quot;</span>}
    row3 := [] <span class="hljs-keyword">string</span> {<span class="hljs-string">&quot;lizard&quot;</span>, <span class="hljs-string">&quot;salamander&quot;</span>}

    <span class="hljs-comment">// &#x4F7F;&#x7528; append() &#x51FD;&#x6570;&#x5C06;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#x6DFB;&#x52A0;&#x5230;&#x4E8C;&#x7EF4;&#x6570;&#x7EC4;&#x4E2D;</span>
    animals = <span class="hljs-built_in">append</span>(animals, row1)
    animals = <span class="hljs-built_in">append</span>(animals, row2)
    animals = <span class="hljs-built_in">append</span>(animals, row3)

    <span class="hljs-comment">// &#x5FAA;&#x73AF;&#x8F93;&#x51FA;</span>
    <span class="hljs-keyword">for</span> i := <span class="hljs-keyword">range</span> animals {
        fmt.Printf(<span class="hljs-string">&quot;Row: %v\n&quot;</span>, i)
        fmt.Println(animals[i])
    }
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x8FD0;&#x884C;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">Row: 0
[fish shark eel]
Row: 1
[bird]
Row: 2
[lizard salamander]
</code></pre>
<h3 id="&#x5411;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x6570;&#x7EC4;">&#x5411;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x6570;&#x7EC4;</h3>
<p>&#x5982;&#x679C;&#x4F60;&#x60F3;&#x5411;&#x51FD;&#x6570;&#x4F20;&#x9012;&#x6570;&#x7EC4;&#x53C2;&#x6570;&#xFF0C;&#x4F60;&#x9700;&#x8981;&#x5728;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x65F6;&#xFF0C;&#x58F0;&#x660E;&#x5F62;&#x53C2;&#x4E3A;&#x6570;&#x7EC4;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4EE5;&#x4E0B;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x6765;&#x58F0;&#x660E;&#xFF1A;</p>
<h4 id="&#x65B9;&#x5F0F;&#x4E00;">&#x65B9;&#x5F0F;&#x4E00;</h4>
<p>&#x5F62;&#x53C2;&#x8BBE;&#x5B9A;&#x6570;&#x7EC4;&#x5927;&#x5C0F;&#xFF1A;</p>
<pre><code class="lang-go">void myFunction(param [<span class="hljs-number">10</span>]<span class="hljs-keyword">int</span>){
    .
    .
    .
}
</code></pre>
<h4 id="&#x65B9;&#x5F0F;&#x4E8C;">&#x65B9;&#x5F0F;&#x4E8C;</h4>
<p>&#x5F62;&#x53C2;&#x672A;&#x8BBE;&#x5B9A;&#x6570;&#x7EC4;&#x5927;&#x5C0F;&#xFF1A;</p>
<pre><code class="lang-go">void myFunction(param []<span class="hljs-keyword">int</span>){
    .
    .
    .
}
</code></pre>
<h4 id="&#x5B9E;&#x4F8B;">&#x5B9E;&#x4F8B;</h4>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x4E0B;&#x4EE5;&#x4E0B;&#x5B9E;&#x4F8B;&#xFF0C;&#x5B9E;&#x4F8B;&#x4E2D;&#x51FD;&#x6570;&#x63A5;&#x6536;&#x6574;&#x578B;&#x6570;&#x7EC4;&#x53C2;&#x6570;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x6307;&#x5B9A;&#x4E86;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x4E2A;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x5E73;&#x5747;&#x503C;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">func</span> getAverage(arr [<span class="hljs-number">5</span>]<span class="hljs-keyword">int</span>, size <span class="hljs-keyword">int</span>) <span class="hljs-keyword">float32</span> {
    <span class="hljs-keyword">var</span> i,sum <span class="hljs-keyword">int</span>
    <span class="hljs-keyword">var</span> avg <span class="hljs-keyword">float32</span>

    <span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i &lt; size;i++ {
        sum += arr[i]
    }

    avg = <span class="hljs-keyword">float32</span>(sum) / <span class="hljs-keyword">float32</span>(size)

    <span class="hljs-keyword">return</span> avg
}
</code></pre>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x6765;&#x8C03;&#x7528;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    <span class="hljs-comment">/* &#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x4E3A; 5 */</span>
    <span class="hljs-keyword">var</span> balance = [<span class="hljs-number">5</span>] <span class="hljs-keyword">int</span> {<span class="hljs-number">1000</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">17</span>, <span class="hljs-number">50</span>}
    <span class="hljs-keyword">var</span> avg <span class="hljs-keyword">float32</span>

    <span class="hljs-comment">/* &#x6570;&#x7EC4;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7ED9;&#x51FD;&#x6570; */</span>
    avg = getAverage( balance, <span class="hljs-number">5</span> )

    <span class="hljs-comment">/* &#x8F93;&#x51FA;&#x8FD4;&#x56DE;&#x7684;&#x5E73;&#x5747;&#x503C; */</span>
    fmt.Printf( <span class="hljs-string">&quot;&#x5E73;&#x5747;&#x503C;&#x4E3A;: %f &quot;</span>, avg )
}

<span class="hljs-keyword">func</span> getAverage(arr [<span class="hljs-number">5</span>] <span class="hljs-keyword">int</span>, size <span class="hljs-keyword">int</span>) <span class="hljs-keyword">float32</span> {
    <span class="hljs-keyword">var</span> i, sum <span class="hljs-keyword">int</span>
    <span class="hljs-keyword">var</span> avg <span class="hljs-keyword">float32</span>

    <span class="hljs-keyword">for</span> i = <span class="hljs-number">0</span>; i &lt; size; i++ {
        sum += arr[i]
    }

    avg = <span class="hljs-keyword">float32</span>(sum) / <span class="hljs-keyword">float32</span>(size)

    <span class="hljs-keyword">return</span> avg
}
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x6267;&#x884C;&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">&#x5E73;&#x5747;&#x503C;&#x4E3A;: 214.399994
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x5B9E;&#x4F8B;&#x4E2D;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x7684;&#x5F62;&#x53C2;&#x5E76;&#x672A;&#x8BBE;&#x5B9A;&#x6570;&#x7EC4;&#x5927;&#x5C0F;&#x3002;</p>
<p>&#x6D6E;&#x70B9;&#x6570;&#x8BA1;&#x7B97;&#x8F93;&#x51FA;&#x6709;&#x4E00;&#x5B9A;&#x7684;&#x504F;&#x5DEE;&#xFF0C;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x8F6C;&#x6574;&#x578B;&#x6765;&#x8BBE;&#x7F6E;&#x7CBE;&#x5EA6;&#x3002;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    a := <span class="hljs-number">1.69</span>
    b := <span class="hljs-number">1.7</span>
    c := a * b      <span class="hljs-comment">// &#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x662F;2.873</span>
    fmt.Println(c)  <span class="hljs-comment">// &#x8F93;&#x51FA;&#x7684;&#x662F;2.8729999999999998</span>
}
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x56FA;&#x5B9A;&#x7CBE;&#x5EA6;&#xFF1A;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">&quot;fmt&quot;</span>

<span class="hljs-keyword">func</span> main() {
    a := <span class="hljs-number">1690</span>           <span class="hljs-comment">// &#x8868;&#x793A;1.69</span>
    b := <span class="hljs-number">1700</span>           <span class="hljs-comment">// &#x8868;&#x793A;1.70</span>
    c := a * b          <span class="hljs-comment">// &#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x662F;2873000&#x8868;&#x793A; 2.873</span>
    fmt.Println(c)      <span class="hljs-comment">// &#x5185;&#x90E8;&#x7F16;&#x7801;</span>
    fmt.Println(<span class="hljs-keyword">float64</span>(c) / <span class="hljs-number">1000000</span>) <span class="hljs-comment">// &#x663E;&#x793A;</span>
}
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../part11/" class="navigation navigation-prev " aria-label="Previous page: Go 语言函数">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../part13/" class="navigation navigation-next " aria-label="Next page: Go 语言指针">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Go 语言数组","level":"1.13","depth":1,"next":{"title":"Go 语言指针","level":"1.14","depth":1,"path":"part13/README.md","ref":"part13/README.md","articles":[]},"previous":{"title":"Go 语言函数","level":"1.12","depth":1,"path":"part11/README.md","ref":"part11/README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"part12/README.md","mtime":"2021-01-19T11:30:22.585Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-01-21T06:29:04.898Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

